<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户列表</title>
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css">

</head>
<body>
<div class="container">
    <div>
        <button id="reback-btn">返回</button>
    </div>
    <h1>用户列表</h1>

    <table class="table table-bordered" id='userTable'>
        <thead>
        <tr>
            <th>客户姓名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>身高</th>
            <th>体重</th>
            <th>收入（万/元）</th>
            <th>是否有车</th>
            <th>是否有房</th>
            <th>是否离异</th>
            <th>民族</th>
            <th>学历</th>
            <th>职业</th>
            <th>户籍所在地</th>
            <th>现居住地</th>
            <th>性格</th>
            <th>朋友接受</th>
            <th>对象要求</th>
            <th>用户编号</th>
        </tr>
        </thead>
    </table>
    <!-- 添加审核通过和审核不通过按钮 -->
    <div>
        <button id="approve-btn">上一页</button>
        <button id="reject-btn">下一页</button>
    </div>
</div>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script>
    $(function () {
        var currentPages = "[[${pageId}]]"
        var totalPages = 0;

        var requestBody = {
            "pageNum": currentPages,
            "pageSize": 50
        };
        console.log("后端传参为："+requestBody);
        // 设置请求的 Content-Type 为 application/json
        $.ajax({
            url: '/user/selectList',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(requestBody),
            success: function (data) {
                currentPages = data.data.current;
                totalPages = data.data.pages;
                var tableHtml = '<tbody>';
                console.log(data);
                var userInfo = data.data.records
                console.log(userInfo);
                for (var i = 0; i < userInfo.length; i++) {
                    tableHtml += '<tr><td>' + userInfo[i].name +
                        '</td><td>' + userInfo[i].gender +
                        '</td><td>' + userInfo[i].age +
                        '</td><td>' + userInfo[i].height +
                        '</td><td>' + userInfo[i].weight +
                        '</td><td>' + userInfo[i].income +
                        '</td><td>' + userInfo[i].hasCar +
                        '</td><td>' + userInfo[i].hasHouse +
                        '</td><td>' + userInfo[i].isDivorced +
                        '</td><td>' + userInfo[i].nation +
                        '</td><td>' + userInfo[i].education +
                        '</td><td>' + userInfo[i].occupation +
                        '</td><td>' + userInfo[i].baseAddress +
                        '</td><td>' + userInfo[i].baseAddress +
                        '</td><td>' + userInfo[i].currentAddress +
                        '</td><td>' + userInfo[i].friendEvaluation +
                        '</td><td>' + userInfo[i].idealType +
                        '</td><td>' + userInfo[i].userId +
                        '</td>';
                }
                tableHtml += '</tbody>';
                // 将 HTML 表格插入到页面中
                $("#userTable").append(tableHtml);
            }
        });
        // 绑定审核通过按钮的点击事件
        $('#approve-btn').click(function () {
            // 发送审核通过请求
            if (currentPages == 1){
                alert("当前第一页");
                return;
            }
            currentPages = currentPages - 1;
            window.location.href = '/userList/'+currentPages;
        });

        // 绑定审核不通过按钮的点击事件
        $('#reject-btn').click(function () {
            // 发送审核不通过请求
            if (currentPages == totalPages){
                alert("当前最后一页");
                return;
            }
            currentPages = currentPages + 1;
            window.location.href = '/userList/'+currentPages;
        });

        // 点击返回
        $('#reback-btn').click(function () {
            // 发送审核通过请求
            window.location.href = '/index';
        });
    });

</script>
</body>
</html>